home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import sys
- import time
- import struct
- from struct import pack, unpack
- from binascii import hexlify
- import cPickle as pickle
- from cStringIO import StringIO
- import weakref
- import warnings
- from persistent.TimeStamp import TimeStamp
- __all__ = [
- 'z64',
- 'p64',
- 'u64',
- 'U64',
- 'cp',
- 'newTimeStamp',
- 'oid_repr',
- 'serial_repr',
- 'tid_repr',
- 'positive_id',
- 'readable_tid_repr',
- 'WeakSet',
- 'DEPRECATED_ARGUMENT',
- 'deprecated37',
- 'deprecated38',
- 'get_pickle_metadata']
- DEPRECATED_ARGUMENT = object()
-
- def deprecated37(msg):
- warnings.warn('This will be removed in ZODB 3.7:\n%s' % msg, DeprecationWarning, stacklevel = 3)
-
-
- def deprecated38(msg):
- warnings.warn('This will be removed in ZODB 3.8:\n%s' % msg, DeprecationWarning, stacklevel = 3)
-
- z64 = '\x00' * 8
- if not sys.hexversion >= 33751040:
- raise AssertionError
-
- def p64(v):
- '''Pack an integer or long into a 8-byte string'''
- return pack('>Q', v)
-
-
- def u64(v):
- '''Unpack an 8-byte string into a 64-bit long integer.'''
- return unpack('>Q', v)[0]
-
- U64 = u64
-
- def cp(f1, f2, l):
- read = f1.read
- write = f2.write
- n = 8192
- while l > 0:
- if n > l:
- n = l
-
- d = read(n)
- if not d:
- break
-
- write(d)
- l = l - len(d)
-
-
- def newTimeStamp(old = None, TimeStamp = TimeStamp, time = time.time, gmtime = time.gmtime):
- t = time()
- ts = TimeStamp(gmtime(t)[:5] + (t % 60,))
- if old is not None:
- return ts.laterThan(old)
-
- return ts
-
-
- def oid_repr(oid):
- if isinstance(oid, str) and len(oid) == 8:
- as_hex = hexlify(oid).lstrip('0')
- if len(as_hex) & 1:
- as_hex = '0' + as_hex
- elif as_hex == '':
- as_hex = '00'
-
- return '0x' + as_hex
- else:
- return repr(oid)
-
- serial_repr = oid_repr
- tid_repr = serial_repr
-
- def readable_tid_repr(tid):
- result = tid_repr(tid)
- if isinstance(tid, str) and len(tid) == 8:
- result = '%s %s' % (result, TimeStamp(tid))
-
- return result
-
- _ADDRESS_MASK = 256 ** struct.calcsize('P')
-
- def positive_id(obj):
- '''Return id(obj) as a non-negative integer.'''
- result = id(obj)
- if result < 0:
- result += _ADDRESS_MASK
- if not result > 0:
- raise AssertionError
-
- return result
-
-
- def get_pickle_metadata(data):
- if data.startswith('(c'):
- global_prefix = 2
- elif data.startswith('c'):
- global_prefix = 1
- else:
- global_prefix = 0
- if global_prefix:
- (modname, classname, rest) = data.split('\n', 2)
- modname = modname[global_prefix:]
- return (modname, classname)
-
- f = StringIO(data)
- u = pickle.Unpickler(f)
-
- try:
- class_info = u.load()
- except Exception:
- err = None
- print 'Error', err
- return ('', '')
-
- if isinstance(class_info, tuple):
- if isinstance(class_info[0], tuple):
- (modname, classname) = class_info[0]
- else:
- (modname, classname) = class_info
- else:
- modname = repr(class_info)
- classname = ''
- return (modname, classname)
-
-
- class WeakSet(object):
- """A set of objects that doesn't keep its elements alive.
-
- The objects in the set must be weakly referencable.
- The objects need not be hashable, and need not support comparison.
- Two objects are considered to be the same iff their id()s are equal.
-
- When the only references to an object are weak references (including
- those from WeakSets), the object can be garbage-collected, and
- will vanish from any WeakSets it may be a member of at that time.
- """
-
- def __init__(self):
- self.data = weakref.WeakValueDictionary()
-
-
- def __len__(self):
- return len(self.data)
-
-
- def __contains__(self, obj):
- return id(obj) in self.data
-
-
- def add(self, obj):
- self.data[id(obj)] = obj
-
-
- def remove(self, obj):
- del self.data[id(obj)]
-
-
- def map(self, f):
- for wr in self.as_weakref_list():
- elt = wr()
- if elt is not None:
- f(elt)
- continue
-
-
-
- def as_weakref_list(self):
- return self.data.data.values()
-
-
-